/*******************************************************************
 *   > File Name: tester.c
 *   > Author: fly
 *   > Mail: XXXXXXXX@icode.com
 *   > Create Time: 2020年07月06日 星期一 19时26分25秒
 ******************************************************************/

#include <main.h>

extern void tester_watchdog(void);
extern int tester_powerlock(void);

int tester_key_with_led_beep(int argc, char * argv[])
{
	u32_t keyup, keydown;

	led_set_status(LED_NAME_LED1, LED_STATUS_OFF);
	led_set_status(LED_NAME_LED2, LED_STATUS_OFF);
	led_set_status(LED_NAME_LED3, LED_STATUS_OFF);
	led_set_status(LED_NAME_LED4, LED_STATUS_OFF);

	beep_set_status(BEEP_STATUS_OFF);

	while(1)
	{
		if(get_key_event(&keyup, &keydown))
		{
			/* KEY UP */
			if(keyup != 0)
			{
				if(keyup & KEY_NAME_LEFT)
				{
					led_set_status(LED_NAME_LED1, LED_STATUS_OFF);
					beep_set_status(BEEP_STATUS_OFF);
				}
				if(keyup & KEY_NAME_DOWN)
				{
					led_set_status(LED_NAME_LED2, LED_STATUS_OFF);
					beep_set_status(BEEP_STATUS_OFF);
				}
				if(keyup & KEY_NAME_RIGHT)
				{
					led_set_status(LED_NAME_LED3, LED_STATUS_OFF);
					beep_set_status(BEEP_STATUS_OFF);
				}
				if(keyup & KEY_NAME_BACK)
				{
					led_set_status(LED_NAME_LED4, LED_STATUS_OFF);
					beep_set_status(BEEP_STATUS_OFF);
				}
			}

			/* KEY DOWN */
			if(keydown != 0)
			{
				if(keydown & KEY_NAME_LEFT)
				{
					serial_printf(0, "KEY_NAME_LEFT\r\n");
					
					led_set_status(LED_NAME_LED1, LED_STATUS_ON);
					beep_set_status(BEEP_STATUS_ON);
				}
				if(keydown & KEY_NAME_DOWN)
				{
					serial_printf(0, "KEY_NAME_DOWN\r\n");
					
					led_set_status(LED_NAME_LED2, LED_STATUS_ON);
					beep_set_status(BEEP_STATUS_ON);
				}
				if(keydown & KEY_NAME_RIGHT)
				{
					serial_printf(0, "KEY_NAME_RIGHT\r\n");
					
					led_set_status(LED_NAME_LED3, LED_STATUS_ON);
					beep_set_status(BEEP_STATUS_ON);
				}
				if(keydown & KEY_NAME_BACK)
				{
					serial_printf(0, "KEY_NAME_BACK\r\n");
					
					led_set_status(LED_NAME_LED4, LED_STATUS_ON);
					beep_set_status(BEEP_STATUS_ON);
				}
                if(keydown & KEY_NAME_MENU)
                {
					serial_printf(0, "KEY_NAME_MENU\r\n");
					
                    tester_powerlock();
                }
                if (keydown & KEY_NAME_UP)
                {
                    serial_printf(0, "KEY_NAME_UP\r\n");

                    tester_watchdog();
                }
			}
		}
	}

	return 0;
}

